package com.ct.controller.sysmenus;

import com.ct.application.commons.vo.StatusRequest;
import com.ct.application.sysrmenus.model.vo.SysMenusVO;
import com.ct.application.sysrmenus.request.SysMenusBatchRequest;
import com.ct.application.sysrmenus.request.SysMenusSaveRequest;
import com.ct.application.sysrmenus.request.SysMenusSearchRequest;
import com.ct.application.sysrmenus.request.SysMenusUpdateRequest;
import com.ct.application.sysrmenus.service.ISysMenusService;
import com.ct.commons.BaseController;
import com.ct.commons.annotation.ApiLog;
import com.ct.commons.annotation.HasAdmin;
import com.ct.commons.annotation.PermissionApi;
import com.ct.commons.aspect.limiter.AccessIpLimiter;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * RBAC-菜单管理
 * @author Auto Generator
 * @since 2023-08-13
 */
@RestController
@PermissionApi(title = "菜单管理模块",path="/api/v1/menu",code = "X1000",sorted = 15)
public class SysMenusController  extends BaseController {

    @Autowired
    private ISysMenusService sysMenusService;

    /**
     * 菜单列表--租户角色绑定
     * @return
     */
    @PostMapping("/menu/system/list")
    @PermissionApi(title = "菜单列表--租户角色绑定",path="/api/v1/menu/system/list",code = "X1001",sorted = 1)
    public List<SysMenusVO> findSystemPage() {
        return sysMenusService.findSystemPageMenu(2L);
    }


    /**
     * 菜单列表
     *
     * @param menusSearchRequest
     * @return
     */
    @PostMapping("/menu/list")
    @PermissionApi(title = "菜单列表",path="/api/v1/menu/list",code = "X1002",sorted = 2)
    public List<SysMenusVO> findPage(@RequestBody SysMenusSearchRequest menusSearchRequest) {
        return sysMenusService.findPageMenu(menusSearchRequest);
    }

    /**
     * 保存后台菜单
     * @param sysMenusSaveRequest
     * @return
     */
    @PostMapping("/menu/save")
    @HasAdmin
    @AccessIpLimiter
    @ApiLog("保存后台菜单")
    @PermissionApi(title = "保存后台菜单",path="/api/v1/menu/save",code = "X1003",sorted = 3)
    public SysMenusVO saveSysMenus(@Validated @RequestBody SysMenusSaveRequest sysMenusSaveRequest){
        return sysMenusService.saveSysMenus(sysMenusSaveRequest);
    }

    /**
     * 修改后台菜单
     * @param sysMenusSaveRequest
     * @return
     */
    @PostMapping("/menu/update")
    @HasAdmin
    @AccessIpLimiter
    @ApiLog("修改后台菜单")
    @PermissionApi(title = "修改后台菜单",path="/api/v1/menu/update",code = "X1004",sorted = 4)
    public SysMenusVO updateSysMenus(@Validated @RequestBody SysMenusUpdateRequest sysMenusSaveRequest){
        return sysMenusService.updateSysMenus(sysMenusSaveRequest);
    }

    /**
     * 根据ID查询后台菜单
     * @param id
     * @return
     */
    @PostMapping("/menu/get/{id}")
    @PermissionApi(title = "根据ID查询后台菜单",path="/api/v1/menu/get/{id}",code = "X1005",sorted = 5)
    public SysMenusVO getSysMenus(@PathVariable("id") Long id){
        return sysMenusService.selectById(id);
    }

    /**
     * 删除菜单
     * @param id
     * @return
     */
    @PostMapping("/menu/del/{id}")
    @HasAdmin
    @AccessIpLimiter
    @ApiLog("删除菜单")
    @PermissionApi(title = "删除菜单",path="/api/v1/menu/del/{id}",code = "X1006",sorted = 6)
    public Boolean delSysMenus(@PathVariable("id") Long id){
        return sysMenusService.deleteById(id);
    }

    /**
     * 根据字段修改状态
     * @param statusRequest
     * @return
     */
    @PostMapping("/menu/update/status")
    @HasAdmin
    @AccessIpLimiter
    @ApiLog("修改状态")
    @PermissionApi(title = "修改状态",path="/api/v1/menu/update/status",code = "X1007",sorted = 7)
    public Boolean updateStatusSysMenus(@Validated @RequestBody StatusRequest statusRequest){
        return sysMenusService.updateStatusSysMenus(statusRequest);
    }

    /**
     * 批量通过
     * @param sysMenusBatchRequest
     * @return
     */
    @PostMapping("/menu/batch/statuss")
    @HasAdmin
    @AccessIpLimiter
    @ApiLog("批量通过")
    @PermissionApi(title = "批量通过",path="/api/v1/menu/batch/statuss",code = "X1008",sorted = 8)
    public Boolean batchStatus(@Validated @RequestBody SysMenusBatchRequest sysMenusBatchRequest){
        return sysMenusService.batchStatus(sysMenusBatchRequest);
    }

    /**
     * 批量禁止
     * @param sysMenusBatchRequest
     * @return
     */
    @PostMapping("/menu/batch/forbiddens")
    @HasAdmin
    @AccessIpLimiter
    @ApiLog("批量禁止")
    @PermissionApi(title = "批量禁止",path="/api/v1/menu/batch/forbiddens",code = "X1009",sorted = 9)
    public Boolean batchForbiddens(@Validated @RequestBody SysMenusBatchRequest sysMenusBatchRequest){
        return sysMenusService.batchForbiddens(sysMenusBatchRequest);
    }

}
